package com.coin.controller;

import java.util.List;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.binance.api.client.BinanceApiClientFactory;
import com.binance.api.client.BinanceApiRestClient;
import com.binance.api.client.domain.TimeInForce;
import com.binance.api.client.domain.account.Account;
import com.binance.api.client.domain.account.DepositAddress;
import com.binance.api.client.domain.account.DepositHistory;
import com.binance.api.client.domain.account.NewOrder;
import com.binance.api.client.domain.account.NewOrderResponse;
import com.binance.api.client.domain.account.Order;
import com.binance.api.client.domain.account.Trade;
import com.binance.api.client.domain.account.TradeHistoryItem;
import com.binance.api.client.domain.account.WithdrawHistory;
import com.binance.api.client.domain.account.request.AllOrdersRequest;
import com.binance.api.client.domain.account.request.CancelOrderRequest;
import com.binance.api.client.domain.account.request.OrderRequest;
import com.binance.api.client.domain.account.request.OrderStatusRequest;
import com.binance.api.client.domain.general.ExchangeInfo;
import com.binance.api.client.domain.market.AggTrade;
import com.binance.api.client.domain.market.BookTicker;
import com.binance.api.client.domain.market.OrderBook;
import com.binance.api.client.domain.market.TickerPrice;
import com.binance.api.client.domain.market.TickerStatistics;
import com.coin.exchange.binance.vo.BnAccountRequestVO;
import com.coin.exchange.binance.vo.BnAllOrdersRequestVO;
import com.coin.exchange.binance.vo.BnCancelOrderRequestVO;
import com.coin.exchange.binance.vo.BnDepositAddrRequestVO;
import com.coin.exchange.binance.vo.BnDepositHisRequestVO;
import com.coin.exchange.binance.vo.BnHisTradesRequestVO;
import com.coin.exchange.binance.vo.BnLimitBuyOrSellRequestVO;
import com.coin.exchange.binance.vo.BnMarketBuyOrSellRequestVO;
import com.coin.exchange.binance.vo.BnMyTradesRequestVO;
import com.coin.exchange.binance.vo.BnOpenOrdersRequestVO;
import com.coin.exchange.binance.vo.BnOrderBookRequestVO;
import com.coin.exchange.binance.vo.BnOrderStatusRequestVO;
import com.coin.exchange.binance.vo.BnTradesRequestVO;
import com.coin.exchange.binance.vo.BnWithdrawHisRequestVO;
import com.coin.exchange.binance.vo.BnWithdrawRequestVO;
import com.coin.framework.bean.ResultForm;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/rest/binance")
public class BinanceController {

	private static Logger logger = LoggerFactory.getLogger(BinanceController.class);

	@ApiOperation(value = "Get the current server time")
	@RequestMapping(value = "/getServiceTime", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultForm<?> getServiceTime() {
		ResultForm<?> resultForm = null;
		try {
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    long serverTime = client.getServerTime();
		    resultForm = ResultForm.createSuccessResultForm(serverTime, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "")
	@RequestMapping(value = "/getExchangeInfo", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultForm<?> getExchangeInfo() {
		ResultForm<?> resultForm = null;
		try {
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    ExchangeInfo exchangeInfo = client.getExchangeInfo();
		    resultForm = ResultForm.createSuccessResultForm(exchangeInfo, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get order book of a symbol")
	@RequestMapping(value = "/getOrderBook", method = RequestMethod.POST)
	public ResultForm<?> getOrderBook(@RequestBody @Valid BnOrderBookRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String symbol = vo.getSymbol();
			Integer limit = vo.getLimit();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    OrderBook orderBook = client.getOrderBook(symbol, limit);
		    resultForm = ResultForm.createSuccessResultForm(orderBook, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get recent trades")
	@RequestMapping(value = "/getTrades", method = RequestMethod.POST)
	public ResultForm<?> getTrades(@RequestBody @Valid BnTradesRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String symbol = vo.getSymbol();
			Integer limit = vo.getLimit();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    List<TradeHistoryItem> list = client.getTrades(symbol, limit);
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get older trades")
	@RequestMapping(value = "/getHistoricalTrades", method = RequestMethod.POST)
	public ResultForm<?> getHistoricalTrades(@RequestBody @Valid BnHisTradesRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String symbol = vo.getSymbol();
			Integer limit = vo.getLimit();
			Long fromId = vo.getFromId();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    List<TradeHistoryItem> list = client.getHistoricalTrades(symbol, limit, fromId);
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "")
	@RequestMapping(value = "/getAggTrades", method = RequestMethod.POST)
	public ResultForm<?> getAggTrades(@RequestBody String symbol) {
		ResultForm<?> resultForm = null;
		try {
//			String symbol = jsonObject.getString("symbol");
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    List<AggTrade> list = client.getAggTrades(symbol);
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get 24 hour price change statistics")
	@RequestMapping(value = "/get24HrPriceStatistics", method = RequestMethod.POST)
	public ResultForm<?> get24HrPriceStatistics(@RequestBody String symbol) {
		ResultForm<?> resultForm = null;
		try {
//			String symbol = jsonObject.getString("symbol");
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    TickerStatistics statistics = client.get24HrPriceStatistics(symbol);
		    resultForm = ResultForm.createSuccessResultForm(statistics, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get 24 hour price change statistics for all symbols")
	@RequestMapping(value = "/getAll24HrPriceStatistics", method = RequestMethod.POST)
	public ResultForm<?> getAll24HrPriceStatistics() {
		ResultForm<?> resultForm = null;
		try {
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    List<TickerStatistics> list = client.getAll24HrPriceStatistics();
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get latest price")
	@RequestMapping(value = "/getPrice", method = RequestMethod.POST)
	public ResultForm<?> getPrice(@RequestBody String symbol) {
		ResultForm<?> resultForm = null;
		try {
//			String symbol = jsonObject.getString("symbol");
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    TickerPrice price = client.getPrice(symbol);
		    resultForm = ResultForm.createSuccessResultForm(price, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get Latest price for all symbols")
	@RequestMapping(value = "/getAllPrices", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultForm<?> getAllPrices() {
		ResultForm<?> resultForm = null;
		try {
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    List<TickerPrice> list = client.getAllPrices();
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get best price/qty on the order book for all symbols")
	@RequestMapping(value = "/getBookTickers", method = {RequestMethod.POST, RequestMethod.GET})
	public ResultForm<?> getBookTickers() {
		ResultForm<?> resultForm = null;
		try {
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
		    BinanceApiRestClient client = factory.newRestClient();
		    List<BookTicker> list = client.getBookTickers();
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get current account information")
	@RequestMapping(value = "/getAccount", method = RequestMethod.POST)
	public ResultForm<?> getAccount(@RequestBody @Valid BnAccountRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    Account account = client.getAccount();
		    resultForm = ResultForm.createSuccessResultForm(account, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get trades")
	@RequestMapping(value = "/getMyTrades", method = RequestMethod.POST)
	public ResultForm<?> getMyTrades(@RequestBody @Valid BnMyTradesRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    List<Trade> list = client.getMyTrades(symbol);
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Submit a withdraw request")
	@RequestMapping(value = "/withdraw", method = RequestMethod.POST)
	public ResultForm<?> withdraw(@RequestBody @Valid BnWithdrawRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String asset = vo.getAsset();
			String address = vo.getAddress();
			String amount = vo.getAmount();
			String name = vo.getName();
			String addressTag = vo.getAddress_tag();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    client.withdraw(asset, address, amount, name, addressTag);
		    resultForm = ResultForm.createSuccessResultForm(null, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Fetch account deposit history")
	@RequestMapping(value = "/getDepositHistory", method = RequestMethod.POST)
	public ResultForm<?> getDepositHistory(@RequestBody @Valid BnDepositHisRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String asset = vo.getAsset();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    DepositHistory history = client.getDepositHistory(asset);
		    resultForm = ResultForm.createSuccessResultForm(history, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Fetch account withdraw history")
	@RequestMapping(value = "/getWithdrawHistory", method = RequestMethod.POST)
	public ResultForm<?> getWithdrawHistory(@RequestBody @Valid BnWithdrawHisRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String asset = vo.getAsset();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    WithdrawHistory history = client.getWithdrawHistory(asset);
		    resultForm = ResultForm.createSuccessResultForm(history, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Fetch deposit address")
	@RequestMapping(value = "/getDepositAddress", method = RequestMethod.POST)
	public ResultForm<?> getDepositAddress(@RequestBody @Valid BnDepositAddrRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String asset = vo.getAsset();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    DepositAddress address = client.getDepositAddress(asset);
		    resultForm = ResultForm.createSuccessResultForm(address, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Check an order's status")
	@RequestMapping(value = "/getOrderStatus", method = RequestMethod.POST)
	public ResultForm<?> getOrderStatus(@RequestBody @Valid BnOrderStatusRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			Long orderId = vo.getOrder_id();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    Order order = client.getOrderStatus(new OrderStatusRequest(symbol, orderId));
		    resultForm = ResultForm.createSuccessResultForm(order, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Cancel an active order")
	@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
	public ResultForm<?> cancelOrder(@RequestBody @Valid BnCancelOrderRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			Long orderId = vo.getOrder_id();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    client.cancelOrder(new CancelOrderRequest(symbol, orderId));
		    resultForm = ResultForm.createSuccessResultForm(null, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get all open orders")
	@RequestMapping(value = "/getOpenOrders", method = RequestMethod.POST)
	public ResultForm<?> getOpenOrders(@RequestBody @Valid BnOpenOrdersRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    List<Order> list = client.getOpenOrders(new OrderRequest(symbol));
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Get all account orders")
	@RequestMapping(value = "/getAllOrders", method = RequestMethod.POST)
	public ResultForm<?> getAllOrders(@RequestBody @Valid BnAllOrdersRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			Integer limit = vo.getLimit();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    List<Order> list = client.getAllOrders(new AllOrdersRequest(symbol).limit(limit));
		    resultForm = ResultForm.createSuccessResultForm(list, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Places a MARKET buy order")
	@RequestMapping(value = "/marketBuy", method = RequestMethod.POST)
	public ResultForm<?> marketBuy(@RequestBody @Valid BnMarketBuyOrSellRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String quantity = vo.getQuantity();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    NewOrderResponse newOrderResponse = client.newOrder(NewOrder.marketBuy(symbol, quantity));
		    resultForm = ResultForm.createSuccessResultForm(newOrderResponse, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Places a MARKET sell order")
	@RequestMapping(value = "/marketSell", method = RequestMethod.POST)
	public ResultForm<?> marketSell(@RequestBody @Valid BnMarketBuyOrSellRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String quantity = vo.getQuantity();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    NewOrderResponse newOrderResponse = client.newOrder(NewOrder.marketSell(symbol, quantity));
		    resultForm = ResultForm.createSuccessResultForm(newOrderResponse, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Places a LIMIT buy order")
	@RequestMapping(value = "/limitBuy", method = RequestMethod.POST)
	public ResultForm<?> limitBuy(@RequestBody @Valid BnLimitBuyOrSellRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String quantity = vo.getQuantity();
			String price = vo.getPrice();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    NewOrderResponse newOrderResponse = client.newOrder(NewOrder.limitBuy(symbol, TimeInForce.GTC, quantity, price));
		    resultForm = ResultForm.createSuccessResultForm(newOrderResponse, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}

	@ApiOperation(value = "Places a LIMIT sell order")
	@RequestMapping(value = "/limitSell", method = RequestMethod.POST)
	public ResultForm<?> limitSell(@RequestBody @Valid BnLimitBuyOrSellRequestVO vo) {
		ResultForm<?> resultForm = null;
		try {
			String apiKey = vo.getApi_key();
			String secretKey = vo.getSecret_key();
			String symbol = vo.getSymbol();
			String quantity = vo.getQuantity();
			String price = vo.getPrice();
			BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(apiKey, secretKey);
		    BinanceApiRestClient client = factory.newRestClient();
		    NewOrderResponse newOrderResponse = client.newOrder(NewOrder.limitSell(symbol, TimeInForce.GTC, quantity, price));
		    resultForm = ResultForm.createSuccessResultForm(newOrderResponse, "成功");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
			resultForm = ResultForm.createErrorResultForm(null, e.getMessage());
		}
		return resultForm;
	}
	
}
